﻿function setShowGoodsDiv() {
    $("#trxz").hide();
    $("#aSaveLebel").html("确认分类");
    $("#selectLevel").hide();
    $("#div_goods_info").show();
};
function setLevel() {
    setShowGoodsDiv();
    var _jsParam = new jsonRow();
    _jsParam.AddCell("ACTION", "doSelectLevel");
    _jsParam.AddCell("ID", $("#txtId").val());
    _jsParam.AddCell("JY_LEVEL1", $("#dplLEVEL_ONE_ID").val());
    _jsParam.AddCell("JY_LEVEL2", $("#dplLEVEL_TWO_ID").val());
    _jsParam.AddCell("JY_LEVEL3", $("#dplLEVEL_THREE_ID").val());
    _jsParam.AddCell("CT_LEVEL1", $("#dplCT_LEVEL_ONE_ID").val());
    _jsParam.AddCell("CT_LEVEL2", $("#dplCT_LEVEL_TWO_ID").val());
    _jsParam.AddCell("CT_LEVEL3", $("#dplCT_LEVEL_THREE_ID").val());
    ajaxComm(_jsParam);
    setLevelDescShow();
};
function setLevelDescShow() {
    $('#sys_cate_name').html('<samp style="padding-left:35px;">优速购商城系统分类：</samp><samp>&gt;</samp><span>' + $('#dplLEVEL_ONE_ID option:selected').text() + '</span><samp>&gt;</samp><span>' + $('#dplLEVEL_TWO_ID option:selected').text() + '</span><samp>&gt;</samp><span>' + $('#dplLEVEL_THREE_ID option:selected').text() + '</span></span>');
    $('#ct_cate_name').html('<samp style="padding-left:35px;">商铺自定义导航分类：</samp><samp>&gt;</samp><span>' + $('#dplCT_LEVEL_ONE_ID option:selected').text() + '</span><samp>&gt;</samp><span>' + $('#dplCT_LEVEL_TWO_ID option:selected').text() + '</span><samp>&gt;</samp><span>' + $('#dplCT_LEVEL_THREE_ID option:selected').text() + '</span></span>');
};
function getGoodsAttrForSave(_jsPost) {
    var $list1 = $('#detail_list .sys-good-detail-hand,#detail_list .good-detail-hand');
    $list1.each(function (i, GoodDetailItem) {
        _jsPost.AddCell("GOODS_ATTRIBUTE_ID" + i, $(this).attr('data-id'));
        _jsPost.AddCell("IS_CUSTOM" + i, $(this).attr('iscustom'));
        $(GoodDetailItem).find("input").each(function (r, goodDetail) {
            _jsPost.AddCell($(this).attr('for') + i, $(this).val()); 
        });
    });
    _jsPost.AddCell("GOODS_ATTR_COUNT", $list1.length );
};
function getGoodsHotLabelForSave(_jsPost) {
    var $list1 = $('#listhotlabelshow .tb-selected');
    $list1.each(function (i, Item) {
        _jsPost.AddCell("LABEL_TEMP_ID" + i, $(this).attr('data-value'));
        _jsPost.AddCell("LABEL_NME" + i, $(this).attr('data-nme')); 
    });
    _jsPost.AddCell("GOODS_HOT_LABEL_COUNT", $list1.length);
};
function getGoodsNormsForSave(_jsPost) {
    var $list1 = $('#good_spec table tbody tr');
    $list1.each(function (i, GoodDetailItem) {
        _jsPost.AddCell("PUB_NORMS_ID" + '_' + i, $(this).attr('data-id')); 
        $(GoodDetailItem).find("input").each(function (r, goodDetail) {
            _jsPost.AddCell($(this).attr('for') + '_' + i, $(this).val()); 
        });
    });
    _jsPost.AddCell("GOODS_NORMS_COUNT", $list1.length);
};
function doSaveGoodsPub(sSid) { 
    var loadi = layer.load('正在保存中…');
    try {
        function closeload() { layer.close(loadi); }
        var _jsParam = new jsonRow();
        _jsParam.AddCell("ACTION", "doSaveGoodsPub");
        _jsParam.AddCell("ID", $('#txtId').val()); 
        //获取数据
        var _jsPost = new jsonRow();
        getGoodsAttrForSave(_jsPost);
        getGoodsHotLabelForSave(_jsPost);
        getGoodsNormsForSave(_jsPost);
        GetFormJson("content", _jsPost);
        _jsPost.AddCell("GOODS_HTML", editor.html());
        _jsPost.AddCell("GOODS_STATUS_SID", sSid);
        _jsPost.AddCell("SHIP_ADDRESS_NME", $("#dplSHIP_ADDRESS_ID").find("option:selected").text().split(' ')[0]);  
        _jsPost.AddCell("GOODS_IMG_COUNT", $('#img_selected img').length);
        $('#img_selected img').each(function (i, GoodimgItem) {
            _jsPost.AddCell("GOODS_IMG_URL" + i, $(this).attr('for'));
        });
        ajaxComm(_jsParam, _jsPost, closeload);
    }
    catch (err) {
        layer.close(loadi);
    }
};

function getBrandAndNorms() {
    var _jsParam = new jsonRow();
    _jsParam.AddCell("ACTION", "dogetBrandAndNorms");
    _jsParam.AddCell("ID", $("#txtId").val());
    ajaxComm(_jsParam);
};

function ShowGoodClassfiy() { 
    $("#div_goods_info").hide();
    $("#selectLevel").show();
};

function ShowGoodsImgList(data) {
    //    $.ploadFile("laytpl", function (script, textStatus) {
    var tpl = HtmlUtil.htmlDecode(document.getElementById('dvImgList_template').innerHTML);
    laytpl(tpl).render(data, function (render) {
        document.getElementById('dvImgList').innerHTML = render;
    });
    //    });
    //    $.ploadFile("laytpl", function (script, textStatus) {
    var tpl = HtmlUtil.htmlDecode(document.getElementById('dvImgPage_template').innerHTML);
    laytpl(tpl).render(data, function (render) {
        document.getElementById('dvImgPage').innerHTML = render;
    });
    //    });
};

function ShowGoodsImgClassfiy(data) {
    //    $.ploadFile("laytpl", function (script, textStatus) {
    var tpl = HtmlUtil.htmlDecode(document.getElementById('dvcateSelMenu_template').innerHTML);
    laytpl(tpl).render(data, function (render) {
        $('#dvcateSelMenu').html(render);
        //document.getElementById('dvcateSelMenu').innerHTML = render;
    });
    //    });
};
